import { ElMessage } from 'element-plus'

type MessageType = 'success' | 'error' | 'info' | 'warning' | 'primary'

function showMessage(type: MessageType, message: string, duration = 2000) {
  ElMessage({
    message,
    type,
    duration
  })
}

export const message = {
  success(msg: string, duration?: number) {
    showMessage('success', msg, duration)
  },
  error(msg: string, duration?: number) {
    showMessage('error', msg, duration)
  },
  info(msg: string, duration?: number) {
    showMessage('info', msg, duration)
  },
  warning(msg: string, duration?: number) {
    showMessage('warning', msg, duration)
  },
  primary(msg: string, duration?: number) {
    showMessage('primary', msg, duration)
  }
}